<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Built-Ins to Evaluate Arithmetic Expressions
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot042.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot044.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc110">8.1</A>&nbsp;&nbsp;Built-Ins to Evaluate Arithmetic Expressions</H2><UL>
<LI><A HREF="umsroot043.html#toc69">Arithmetic Evaluation vs Arithmetic Constraint Solving</A>
</UL>

<A NAME="@default385"></A>
Unlike other languages, Prolog usually interprets an arithmetic expression like
<B>3 + 4</B> as a compound term with functor <B>+</B> and two arguments.
Therefore a query like <B>3 + 4 = 7</B> fails because a compound term does not
unify with a number. The evaluation of an arithmetic expression has to be
explicitly requested by using one of the built-ins described below.<BR>
<BR>
<A NAME="@default386"></A>
The basic predicate for evaluating an arithmetic expression is <A HREF="../bips/kernel/arithmetic/is-2.html"><B>is/2</B></A><A NAME="@default387"></A>.
Apart from that only the 6 arithmetic comparison predicates evaluate
arithmetic expressions automatically.
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>Result is Expression</B><DD CLASS="dd-description">
<A NAME="@default388"></A>
<B>Expression</B> is a valid arithmetic expression and <B>Result</B>
is an uninstantiated variable or a number.
The system evaluates <B>Expression</B> which yields a numeric result.
This result is then unified with <B>Result</B>.
An error occurs if <B>Expression</B> is not a valid arithmetic expression or
if the evaluated value and <B>Result</B> are of different types.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 &lt; Expr2</B><DD CLASS="dd-description">
<A NAME="@default389"></A>
succeeds if (after evaluation and type coercion) Expr1 is less than Expr2.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 &gt;= Expr2</B><DD CLASS="dd-description">
<A NAME="@default390"></A>
succeeds if (after evaluation and type coercion) Expr1 is greater or equal to Expr2.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 &gt; Expr2</B><DD CLASS="dd-description">
<A NAME="@default391"></A>
succeeds if (after evaluation and type coercion) Expr1 is greater than Expr2.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 =&lt; Expr2</B><DD CLASS="dd-description">
<A NAME="@default392"></A>
succeeds if (after evaluation and type coercion) Expr1 is less or equal to Expr2.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 =:= Expr2</B><DD CLASS="dd-description">
<A NAME="@default393"></A>
succeeds if (after evaluation and type coercion) Expr1 is equal to Expr2.<BR>
<BR>
<DT CLASS="dt-description"><B>Expr1 =\= Expr2</B><DD CLASS="dd-description">
<A NAME="@default394"></A>
succeeds if (after evaluation and type coercion) Expr1 is not equal to Expr2.
</DL>
<A NAME="toc69"></A>
<H3 CLASS="subsection"><A NAME="htoc111">8.1.1</A>&nbsp;&nbsp;Arithmetic Evaluation vs Arithmetic Constraint Solving</H3>
This chapter deals purely with the evaluation of arithmetic expressions
containing numbers. No uninstantiated variables must occur within the
expressions at the time they are evaluated. This is exactly like
arithmetic evaluation in procedural languages.<BR>
<BR>
As opposed to that, in arithmetic constraint solving one can state
equalities and inequalities involving variables, and a constraint
solver tries to find values for these variables which satisfy these
constraints. Note that ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> uses the same syntax in both cases,
but different implementations providing different solving capabilities.
See the chapter <B>Common Solver Interface</B> in the
<A HREF="../libman/libman.html">Constraint Library Manual</A> for an overview.<BR>
<BR>
<HR>
<A HREF="umsroot042.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot044.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
